
#import <Foundation/Foundation.h>
#import <FMDB/FMDB.h>

#ifdef DEBUG
#define debugLog(...) NSLog(__VA_ARGS__)
#define debugMethod() NSLog(@"%s", __func__)
#else
#define debugLog(...)
#define debugMethod()
#endif

#define db_path [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]
#define db_name @"sqlite.db"
// SQL 语句
#define SQL_TABLE_EXIST(name) [NSString stringWithFormat:@"sqlite_master where type='table' and name='%@'",name]
#define SQL_TABLE_LISTNAME(name) [NSString stringWithFormat:@"PRAGMA table_info(%@)",name]
#define SQL_TABLE_ALTER(tablename,attr,type) [NSString stringWithFormat:@"ALTER TABLE %@ ADD column %@ %@",tablename,attr,type]

typedef void(^IsSuccBlock)(BOOL isSuccess);

@interface TRManager : NSObject

+(TRManager *)manager;
/**
 * 创建详细数据表，带有多个字段
 */
-(void)createTable:(NSString *)tableName
            andSql:(NSString *)sql
         isSuccess:(IsSuccBlock)isSuccBlock;
- (void)createTable:(NSString *)tableName andSql:(NSString *)sql;
/**
 * 查询数据
 * 格式形如: tablename where 字段='?'
 */
-(void)selectDataWithSql:(NSString *)sql
                finished:(void(^)(FMResultSet *result))finished;

- (FMResultSet *)selectDataWithSql:(NSString *)sql;
/**
 * 插入数据(注意检查数据是否存在)
 * 格式形如: tablename(字段1,字段2..) values (?,?..)
 */
-(void)insertDataWithSql:(NSString *)sql
               isSuccess:(IsSuccBlock)isSuccBlock;
/**
 * 删除数据(注意检查数据是否存在)
 * 格式形如: tablename where 字段1='?'
 */
-(void)deleteDataWithSql:(NSString *)sql
               isSuccess:(IsSuccBlock)isSuccBlock;
/**
 * 更新数据(注意检查数据是否存在) 
 * 格式形如: tablename set 字段1='?',字段2='?' where 字段='?'
 */
-(void)updateDataWithSql:(NSString *)sql
               isSuccess:(IsSuccBlock)isSuccBlock;

- (void)executeUpdate:(NSString *)sql;
- (void)executeUpdate:(NSString *)sql
            isSuccess:(IsSuccBlock)isSuccBlock;

- (FMResultSet *)executeQuery:(NSString *)sql;
- (void)executeQuery:(NSString *)sql
            finished:(void(^)(FMResultSet *result))finished;
@end
